#include <iostream>
#include "Sock.hh"
#include "Protocol.hh"
using namespace std;
using namespace tom_protocol;
void usage(const string &proc)
{
    cout << "\nUsage: " << proc << " port\n";
}
// .Client  127.0.0.1 8080
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        usage(argv[0]);
        exit(1);
    }
    string server_ip = argv[1];
    uint16_t server_port = atoi(argv[2]);
    Sock sock;
    int sockfd = sock.Socket();
    if (!sock.Connect(sockfd, server_ip, server_port))
    {
        perror("Connect");
        exit(2);
    }
    while (true)
    {
        Request req(10, 20, '+');
        string s = req.Serialize(); // 序列化与反序列化是正常的.
        cout << s << endl;
        Send(sockfd,s);
        string r=Recv(sockfd);
        Response resp;
        resp.Deserialize(r);
        cout<<resp._code<<" : "<<resp._result<<endl;

        sleep(1);
        /////////////////////////test//////////////////////////////////////////
        //   cout<<s<<endl;
        // // Send(sockfd,s);
        // // string r=Recv(sockfd);
        //  Response resp(30,60);
        //  //req.Deserialize(s);
        //  string r=resp.Serialize();
        //  cout<<req._x<<req._op<<req._y<<endl;
        //  cout<<"r:"<<r<<endl;
    }
    return 0;
}
